﻿<%@ WebHandler Language="C#" Class="SysUser_GetByPage" %>

using System;
using System.Web;
using System.Text;
using Newtonsoft.Json;
public class SysUser_GetByPage : IHttpHandler , System.Web.SessionState.IReadOnlySessionState
{
    
    public void ProcessRequest (HttpContext context) 
    {
        OTS.Common.Page<OTS.Model.customDetail> page = new OTS.Common.Page<OTS.Model.customDetail>();
        if (!OTS.BaseLogin.validataModule(context, (int)OTS.enumSysRight.CustomManager))
        {
            page.success = false;
            page.msg = "非法操作！";
        }
        else
        {
            string limit = context.Request["limit"];
            string start = context.Request["start"];
            string realname = context.Request["realname"];
            string loginname = context.Request["loginname"];
            string type = context.Request["type"];
            int limitInt = 20;
            int startInt = 0;
            if (null != limit && OTS.Common.Help.IsNumber(limit)) limitInt = int.Parse(limit);
            if (null != start && OTS.Common.Help.IsNumber(start)) startInt = int.Parse(start);
            
            if (null == realname) realname = "";
            if (null == loginname) loginname = "";
            if (null == type) {
                type = "";
            }
            else if (type == "-1")
            {
                type = "";
            }
               
            OTS.BLL.CustomBLL bll = new OTS.BLL.CustomBLL();


            if (realname == "" && loginname == "" && type=="")
            {
                 page = bll.GetListByPage(startInt, limitInt, "");
            }    
            
            else
            {
                string strWhere = " 1=1 ";
                if (realname != "")
                {
                    strWhere += " AND cusName like '%" + OTS.DAL.DBUtility.Database.GetSQLString(realname) + "%'";
                }
                if (loginname != "")
                {
                    strWhere += " AND cusLoginName like '%" + OTS.DAL.DBUtility.Database.GetSQLString(loginname) + "%'";
                }
                if (type == "0" || type == "1")
                {
                    strWhere += " AND cusType =" + OTS.DAL.DBUtility.Database.GetSQLString(type)  ;
                }
                page = bll.GetListByPage(startInt, limitInt,  strWhere);
            }



        } 
        context.Response.ContentType = "application/x-json";
        context.Response.Charset = "utf-8";
        context.Response.Write(JavaScriptConvert.SerializeObject(page));
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}